/*!
 * \file frct_set_session_private.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    int i_ret = 0;
    L7_session *p_st_session = NULL;
    void *p_session_private = NULL;

    i_ret = frct_set_session_private(p_st_session, p_session_private);

    CU_ASSERT_EQUAL(i_ret,1);
    return;
}

static void __case2(void)
{
    int i_ret = 0;
    L7_session *p_st_session = NULL;
    void *p_session_private = NULL;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    memset(p_st_session,0x00,sizeof(L7_session));

    p_st_session->p_session_private = frmalloc(2);
    p_session_private = frmalloc(2);

    i_ret = frct_set_session_private(p_st_session, p_session_private);

    CU_ASSERT_EQUAL(i_ret,2);

    frfree(p_st_session->p_session_private);
    frfree(p_session_private);
    frfree(p_st_session);
    return;
}

static void __case3(void)
{
    int i_ret = 0;
    L7_session *p_st_session = NULL;
    void *p_session_private = NULL;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    memset(p_st_session,0x00,sizeof(L7_session));

    p_session_private = frmalloc(2);

    i_ret = frct_set_session_private(p_st_session, p_session_private);

    CU_ASSERT_EQUAL(i_ret,0);

    frfree(p_session_private);
    frfree(p_st_session);
    return;
}


int add_suite_frct_set_session_private(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frct_comm frct_set_session_private()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);

    return FR_SUCC;
}
